<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover" />
    <title>部门管理</title>
    <link rel="stylesheet" href="{{asset('/addons/jquery-weui-build/css/weui.min.css')}}">
    <link rel="stylesheet" href="{{asset('/addons/jquery-weui-build/css/jquery-weui.css')}}">
    <link rel="stylesheet" href="{{asset('/css/system/iconfont.css')}}">
    @if($skinid == 3)
        <link rel="stylesheet" href="/css/system/common.css?v=2018121301">
        <link rel="stylesheet" href="/css/system/group-manage.css">
    @elseif($skinid == 1)
        <link rel="stylesheet" href="/css/theme-blue/system/common.css">
        <link rel="stylesheet" href="/css/theme-blue/system/group-manage.css">
    @elseif($skinid == 2)
        <link rel="stylesheet" href="/css/theme-pink/system/iconfont-pink.css">
        <link rel="stylesheet" href="/css/theme-pink/system/common.css">
        <link rel="stylesheet" href="/css/theme-pink/system/group-manage.css">
    @endif
    @include('sysadmin.head')
</head>
<body ontouchstart>
<div class="mian-container">
    <div class="group-manage">
        <div class="weui-search-bar" id="searchBar">
          {{--<form class="weui-search-bar__form">
            <div class="weui-search-bar__box">
              <i class="weui-icon-search"></i>
              <input type="search" class="weui-search-bar__input" id="searchInput" placeholder="搜索" required="">
              <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
            </div>
            <label class="weui-search-bar__label" id="searchText">
              <i class="weui-icon-search"></i>
              <span>搜索</span>
            </label>
          </form>--}}
          <a  href="javascript:void(0);" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>
        </div>
        <div class="group-flex weui-flex">
          <div class="weui-flex__item">
              <a class="create-group" href="javascript:void(0);" data-id="1"><i class="icon iconfont icon-unie60f"></i>创建一级部门</a>
          </div>
          <div class="weui-flex__item">
              <a class="delete-group" href="javascript:void(0);"><i class="icon iconfont icon-jianshao"></i>删除部门</a>
          </div>
        </div>
        @foreach($groups as $g)
            <div class="first-floor weui-cells floor-delete">
                <div class="weui-cell">
                    <div class="weui-cell__hd"><img class="floor-img" src="/img-theme-blue/group-floora{{$skinid}}.png"></div>
                    <div class="weui-cell__bd">
                        <p class="first-name">{{$g['group_name']}}</p>
                        <i data-id="{{$g['id']}}" data-name="{{$g['group_name']}}" class="icon iconfont icon-xiugai "></i>
                        <i data-id="{{$g['id']}}" class="icon iconfont icon-shanchu3 icon-delete"></i>
                    </div>
                    <div class="weui-cell__ft">
                        <a href="{{url('/sysadmin/group/set-member?groupid='.$g['id'])}}"><i class="icon iconfont icon-tubiao05"></i>成员管理</a>
                        <a class="addson-group1" data-id="{{$g['id']}}" href="javascript:void(0);"><i class="icon iconfont icon-_tianjiazibumen"></i>添加子部门</a>
                    </div>
                </div>
                @foreach($g['child'] as $gc)
                    <div class="second-floor floor-delete">
                        <div class="weui-cell">
                            <div class="weui-cell__hd"><img class="floor-img" src="/img-theme-blue/group-floorb{{$skinid}}.png"></div>
                            <div class="weui-cell__bd">
                                <p class="first-name">{{$gc['group_name']}}</p>
                                <i data-id="{{$gc['id']}}" data-name="{{$gc['group_name']}}" class="icon iconfont icon-xiugai"></i>
                                <i data-id="{{$gc['id']}}" class="icon iconfont icon-shanchu3 icon-delete"></i>
                            </div>
                            <div class="weui-cell__ft">
                                <a href="{{url('/sysadmin/group/set-member?groupid='.$gc['id'])}}"><i class="icon iconfont icon-tubiao05"></i>成员管理</a>
                                <a class="addson-group2" data-id="{{$gc['id']}}" href="javascript:void(0);"><i class="icon iconfont icon-_tianjiazibumen"></i>添加子部门</a>
                            </div>
                        </div>
                        @foreach($gc['child'] as $gcc)
                            <div class="third-floor weui-cell floor-delete">
                                <div class="weui-cell__hd"><img class="floor-img" src="/img-theme-blue/group-floorc{{$skinid}}.png"></div>
                                <div class="weui-cell__bd">
                                    <p class="first-name">{{$gcc['group_name']}}</p>
                                    <i data-id="{{$gcc['id']}}" data-name="{{$gcc['group_name']}}" class="icon iconfont icon-xiugai"></i>
                                    <i data-id="{{$gcc['id']}}" class="icon iconfont icon-shanchu3 icon-delete"></i>
                                </div>
                                <div class="weui-cell__ft">
                                    <a href="{{url('/sysadmin/group/set-member?groupid='.$gcc['id'])}}"><i class="icon iconfont icon-tubiao05"></i>成员管理</a>
                                </div>
                            </div>
                        @endforeach
                    </div>
                @endforeach
            </div>
        @endforeach
        {!! csrf_field() !!}
    </div>
</div>
@include('sysadmin.admin-caidan')
<script src="{{asset('/kaohe/js/jquery-2.1.4.min.js')}}"></script>
<script src="{{asset('/addons/jquery-weui-build/js/fastclick.js')}}"></script>
<script>
    $(function() {
        document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + 'px';
        FastClick.attach(document.body);
    });
</script>
<script src="{{asset('/addons/jquery-weui-build/js/jquery-weui.min.js')}}"></script>
<script>
    $(document).ready(function(){
        $('.kaohe-item').click(function(){
            $('.show-hidden').toggle();
        })
        $('.admin-item').click(function(){
            $('.front-show-hidden').toggle();
        });
        //创建一级部门
        $('.create-group').click(function(){
            $.prompt({
              title: '创建部门',
              text: '请为新部门输入名称',
              input: '',
              empty: false, // 是否允许为空
              onOK: function (input) {
                //点击确认
                  input   =   input.replace(/\s+/g,"");
                  if(input.length == 0){
                      $.toast('不能为空',"text");
                      return false;
                  }
                  if(input.length > 9){
                      $.toast('长度不能超过9',"text");
                      return false;
                  }
                  var token = $('input[name=_token]').val();
                  $.ajax({
                      'url': '/sysadmin/group/add-group?_token='+token+'&fid=0',
                      'type': 'POST',
                      'data': '&name='+input,
                      error: function (request) {
                          $.toast('网络错误',"text");
                      },
                      success: function (data) {
                          if (data.status == 'success') {
                              $.toast("操作成功");
                              setTimeout(function(){ window.location.href='/sysadmin/group/index';}, 1000);
                          } else {
                              $.toast(data.msg,"text");
                          }
                      },
                  });
              },
              onCancel: function () {
                //点击取消
              }
            });
        })
        //添加子部门
        $('body').on('click','.addson-group1',function(){
            var that = this;
            var fid = $(this).attr('data-id');
            $.prompt({
              title: '创建部门',
              text: '请为新部门输入名称',
              input: '',
              empty: false, // 是否允许为空
              onOK: function (input) {
                //点击确认
                  var token = $('input[name=_token]').val();
                  $.ajax({
                      'url': '/sysadmin/group/add-group?_token='+token+'&fid='+fid,
                      'type': 'POST',
                      'data': '&name='+input,
                      error: function (request) {
                          console.log("error");
                      },
                      success: function (data) {
                          if (data.status == 'success') {
                              $.toast("操作成功");
                              setTimeout(function(){ window.location.href='/sysadmin/group/index';}, 1000);
                          } else {
                              console.log("error");
                          }
                      },
                  });
              },
              onCancel: function () {
                //点击取消
              }
            });
        })
         $('body').on('click','.addson-group2',function(){
            var that = this;
             var fid = $(this).attr('data-id');
            $.prompt({
              title: '创建部门',
              text: '请为新部门输入名称',
              input: '',
              empty: false, // 是否允许为空
              onOK: function (input) {
                //点击确认
                  var token = $('input[name=_token]').val();
                  $.ajax({
                      'url': '/sysadmin/group/add-group?_token='+token+'&fid='+fid,
                      'type': 'POST',
                      'data': '&name='+input,
                      error: function (request) {
                          console.log("error");
                      },
                      success: function (data) {
                          if (data.status == 'success') {
                              $.toast("操作成功");
                              setTimeout(function(){ window.location.href='/sysadmin/group/index';}, 1000);
                          } else {
                              console.log("error");
                          }
                      },
                  });
              },
              onCancel: function () {
                //点击取消
              }
            });
        })
        //删除部门
        $('.delete-group').click(function(){
            $('.icon-shanchu3').toggle();
        })
        $('.icon-delete').click(function(){
            var that=this;
            var gid = $(this).attr('data-id');
            $.confirm({
              title: '删除',
              text: '确认删除部门，该部门下成员会放到默认部门“我的同事”中',
              onOK: function () {
                  var token = $('input[name=_token]').val();
                  $.ajax({
                      'url': '/sysadmin/group/del-group?_token='+token+'&groupid='+gid,
                      'type': 'POST',
                      'data': '',
                      error: function (request) {
                          console.log("error");
                      },
                      success: function (data) {
                          if (data.status == 'success') {
                              $.toast("操作成功");
                              setTimeout(function(){ window.location.href='/sysadmin/group/index';}, 1000);
                          } else {
                              $.toast(data.msg,"text");
                          }
                      },
                  });

              },
              onCancel: function () {
              }
            });            
        })
        $('.icon-xiugai').click(function(){
            var fid = $(this).attr('data-id');
            var fname = $(this).attr('data-name');
            $.prompt({
                title: '修改部门名称',
                text: '',
                input: fname,
                empty: false, // 是否允许为空
                onOK: function (input) {
                    //点击确认
                    input   =   input.replace(/\s+/g,"");
                    if(input.length == 0){
                        $.toast('不能为空',"text");
                        return false;
                    }
                    if(input.length > 9){
                        $.toast('长度不能超过9',"text");
                        return false;
                    }
                    var token = $('input[name=_token]').val();
                    $.ajax({
                        'url': '/sysadmin/group/modify-group?_token='+token+'&groupid='+fid,
                        'type': 'POST',
                        'data': '&name='+input,
                        error: function (request) {
                            $.toast('网络错误',"text");
                        },
                        success: function (data) {
                            if (data.status == 'success') {
                                $.toast("操作成功");
                                setTimeout(function(){ window.location.reload();}, 1000);
                            } else {
                                $.toast(data.msg,"text");
                            }
                        },
                    });
                },
                onCancel: function () {
                    //点击取消
                }
            });
        });
    })
</script>
</body>
</html>